package thinkingJava.chapter09;

import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Scanner;

public class AdapteredRandomDoubles extends RandomDoubles implements Readable {

	private int count;
	public AdapteredRandomDoubles(int count) {
		this.count = count;
	}
	public int read(CharBuffer cb) throws IOException {
		if (count-- == 0) {
			return -1;
		}
		cb.append(Double.toString(next()) + "    ");
		return cb.length();
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(new AdapteredRandomDoubles(7));
		while(sc.hasNextDouble()) {
			System.out.println(sc.nextDouble());
		}
	}
}
